import request from '@/utils/request'

/**
 * 帐号登录
 * @param {String} account - 用户名
 * @param {String} password - 密码
 * @returns Promise
 */
export const userRegister = (params) => {
  return request('/api/index/register', 'post', params)
}

/**
 * 获取验证码
 * @param {String} type - 0-注册 1-找回密码 2-登陆
 * @param {String} phone 手机号
 */
export const getSendSms = (phone, type = 0) => {
  return request('/api/index/sendSms', 'get', { type, phone })
}

/**
 * 获取图形验证码
 * @param {String} type - 0-注册 1-找回密码 2-登陆
 * @param {String} phone 手机号
 */
export const getVerify = () => {
  return request('/api/index/verify')
}

/**
 * 获取邀请列表
 */
export const getShare = () => {
  return request('/api/user/share')
}

/**
 * 获取间接邀请列表
 */
export const child_share = (id) => {
  return request('/api/user/child_share','get',{id:id})
}

/**
 * 获取邀请二维码
 */
export const shareInfo = () => {
  return request('/api/user/shareInfo')
}

/**
 * 刷新token
 */
export const refreshToken = () => {
  return request('/api/user/flush')
}

/**
 * 找回密码
 * @param {String} verify
 * @param {String} phone 手机号
 * @param {String} password 密码
 */
export const resetPass = (data) => {
  return request('/api/index/forget', 'post', data)
}

/**
 * 登录 ro 验证码登录
 * @param {String} phone
 * @param {String} password
 * @param {String} verify
 */
export const login = (params) => {
  return request('/api/index/login', 'post', params)
}

/**
 * 获取用户信息
 * @returns
 */
export const getUserInfo = () => {
  return request('/api/user/data', 'get')
}

/**
 * 更新用户信息
 * @param {*} params
 * @returns
 */
export const uploadUserInfo = (params) => {
  return request('/api/user/modInfo', 'post', params)
}

/**
 * 修改绑定手机号
 * @param {String} phone 手机号
 * @param {String} verify 验证码
 * @returns
 */
export const uploadPhone = (data) => {
  return request('/api/user/modPhone', 'post', data)
}

// 收货地址列表
export const getAddressList = () => {
  return request('/api/address/lists', 'get')
}
// 修改新增地址
export const addAddress = (params) => {
  return request('/api/address/add', 'post', params)
}
// 删除地址
export const delAddress = (id) => {
  return request('/api/address/del', 'get', { id })
}
/**
 * 获取地址详情
 */
export const getAddressDetail = (id) => {
  return request('/api/address/info', 'get', { id })
}

/**
 * 上传
 * @returns
 */
export const upload = (data) => {
  return request('/api/upload/upload', 'post', data)
}


export default {
	userRegister,
	getSendSms,
	getVerify,
	refreshToken,
	resetPass,
	login,
	getUserInfo,
	uploadUserInfo,
	uploadPhone,
	getAddressList,
	addAddress,
	delAddress,
	getAddressDetail,
	upload,
	getShare,
	child_share,
	shareInfo
}